package main

import (
	"context"
	"fmt"
	"github.com/apache/thrift/lib/go/thrift"
	"os"
	"rpc/thrift/t2/rpc"
)

const NetworkAddr  = "127.0.0.1:9000"

type RpcServImpl struct {}

func (this *RpcServImpl) FunCall(ctx context.Context, callTime int64, funCode string, paramMap map[string]string) (r []string, err error){
	fmt.Println("funcall",callTime,funCode,paramMap)
	for k,v := range paramMap{
		r = append(r,k+v)

	}
	return r,nil
}


func main() {

	// 传输方式 以frame为单位进行传输，非阻塞式服务中使用
	TransportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

	// 传输格式 二进制
	ProtocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	// ProtocolFactory := thrift.NewTCompactProtocolFactory()


	ServerTransport,err := thrift.NewTServerSocket(NetworkAddr)
	if err != nil {
		fmt.Println("err",err)
		os.Exit(1)
	}

	handler := &RpcServImpl{}
	Processor := rpc.NewRpcDemoProcessor(handler)
	server := thrift.NewTSimpleServer4(Processor,ServerTransport,TransportFactory,ProtocolFactory)
	fmt.Println("thrift server is ",NetworkAddr)
	server.Serve()
}
